home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / borland / jnfb88.zip / USETC.ZIP / FILECOPY.C < prev    next >
Text File  |  1987-05-17  |  866b  |  34 lines

  1. /********************************************************************
  2. *  F I L E C O P Y
  3. *
  4. *  Copy the input stream to the output stream.  Return 0 if the
  5. *  copy is successful or EOF for any I/O error.
  6. ********************************************************************/
  7.  
  8. #include <stdio.h>
  9.  
  10. int
  11. filecopy(fin, fout)
  12. FILE *fin;    /* input stream pointer */
  13. FILE *fout;    /* output stream pointer */
  14. {
  15.     int ch;    /* holds ASCII characters and EOF */
  16.     int rcode;    /* return code */
  17.  
  18.     /*
  19.      *  Copy input to output until end of file is reached
  20.      *  or an I/O error occurs.
  21.      */
  22.     rcode = 0;
  23.     while ((ch = getc(fin)) != EOF)
  24.         if (putc(ch, fout) == EOF) {
  25.             rcode = EOF;    /* output error */
  26.             break;
  27.         }
  28.  
  29.     if (ferror(fin))
  30.         rcode = EOF;        /* input error */
  31.  
  32.     return (rcode);
  33. }
  34.